package com.djf.Scrm.dataRelay.controller;

import com.djf.Scrm.dataRelay.dao.UserInfoDao;
import com.djf.Scrm.dataRelay.dao.UserInfoRq;
import com.djf.Scrm.dataRelay.enums.ResultCode;
import com.djf.Scrm.dataRelay.service.WxService;
import com.djf.Scrm.dataRelay.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RequestMapping("/wechat")
@RestController
public class WXController {

    @Autowired
    private WxService wxService;
    @Autowired
    JdbcTemplate jdbcTemplate;

    @RequestMapping("/test")
    public List<Map<String,Object>> test(){
        String sql = "select * from sys_user";
        List<Map<String,Object>> list_map=jdbcTemplate.queryForList(sql);
        return list_map;
    }

    @PostMapping("/loginCode")
    public Result getWechat(@RequestBody UserInfoRq userInfoRq){
        Result<Object> result = new Result<>();
        try {
            UserInfoDao wechat = wxService.getWechat(userInfoRq);
            result.setCode(ResultCode.SUCCESS.code());
            result.setData(wechat);
        }catch (Exception e){
            result.setCode(ResultCode.FAIL.code());
            result.setMsg(e.getMessage());
        }

        return result;
    }





}
